package cn.qicaiwang.open.app.controller;


import cn.qicaiwang.open.app.dto.PageDTO;
import cn.qicaiwang.open.app.entity.FaBanner;
import cn.qicaiwang.open.app.server.DataManagerService;
import cn.qicaiwang.open.common.enums.ResultStatusCodeEnum;
import cn.qicaiwang.open.common.response.ResponseResult;
import org.springframework.web.bind.annotation.*;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;


import javax.annotation.Resource;

@RestController
@RequestMapping("/qcwapp/dataBase")
public class DataBaseController {
    @Resource
    private DataManagerService dataManagerService;

    //轮播图数据表新增或编辑
    @PostMapping("/addOrUpdateFaBanner")
    public  ResponseResult addOrUpdateFaBanner(@RequestBody FaBanner faBanner){
        ResponseResult res=new ResponseResult(ResultStatusCodeEnum.HTTP_ERROR.getCode(),ResultStatusCodeEnum.HTTP_ERROR.getDesc());
        try {
            res=dataManagerService.addOrEditInBanner(faBanner);
        }catch (Exception e){
            e.printStackTrace();
        }
        return res;
    }

    //轮播图数据表删除
    @GetMapping("/deleteFaBanner")
    public  ResponseResult deleteFaBanner(@RequestParam int id){
        ResponseResult res=new ResponseResult(ResultStatusCodeEnum.HTTP_ERROR.getCode(),ResultStatusCodeEnum.HTTP_ERROR.getDesc());
        try {
            res=dataManagerService.delBanner(id);
        }catch (Exception e){
            e.printStackTrace();
        }
        return res;
    }

    //轮播图数据表查询
    @PostMapping("/getFaBannerList")
    public  ResponseResult getFaBannerList(@RequestBody FaBanner faBanner,Page page){
        ResponseResult res=new ResponseResult(ResultStatusCodeEnum.HTTP_ERROR.getCode(),ResultStatusCodeEnum.HTTP_ERROR.getDesc());
        try {
            Page<FaBanner> pages=dataManagerService.getFaBannerList(faBanner,page);
            res.setCode(ResultStatusCodeEnum.HTTP_SUCCESS.getCode());
            res.setData(pages);
            if(page.getRecords().size()==0){
                res.setMsg("暂无数据");
            }else{
                res.setMsg(ResultStatusCodeEnum.HTTP_SUCCESS.getDesc());
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return res;
    }
}
